package org.ufinity.hsms.common.application;


import java.util.LinkedList;
import java.util.List;

import org.ufinity.hsms.common.command.CommandService;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;

public class HSMApplication extends Application {

	private static HSMApplication context;

	private List<Activity> activityList = new LinkedList<Activity>();

	public HSMApplication() {
		super();
		context = this;
	}

	@Override
	public void onCreate() {
		context = this;
		super.onCreate();
		
		Intent commandServiceIntent = new Intent(this, CommandService.class);
		startService(commandServiceIntent);
	}
	// 添加Activity到容器中
	public void addActivity(Activity activity) {
		activityList.add(activity);
	}

	public int getActivityList() {
		return activityList.size();
	}

	// 遍历Activity并finish
	public void exit() {

		for (Activity activity : activityList) {
			if (activity != null && !activity.isFinishing()) {
				activity.finish();
			}
		}
		System.exit(0);
	}

	public static HSMApplication getContext() {
		return context;
	}

}
